#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#if 1
#define MIN_XY  -500
#define MAX_XY  500
#define MIN_N   1
#define MAX_N   10000
#define CASES   100
#else
#define MIN_XY  -5
#define MAX_XY  5
#define MIN_N   1
#define MAX_N   40
#define CASES   50
#endif

int gen_int(int Min, int Max)
{
    return Min + rand() % (Max-Min+1);
}

#if 1
/* Text output. */
int main()
{
    int t;
    for (t = 0; t < CASES; t++)
    {
        int x0 = gen_int(MIN_XY, MAX_XY);
        int y0 = gen_int(MIN_XY, MAX_XY);
        int i, n = gen_int(MIN_N, MAX_N);
        printf("%d %d %d\n", x0, y0, n);
        for (i = 0; i < n; i++)
        {
            int x = gen_int(MIN_XY, MAX_XY);
            int y = gen_int(MIN_XY, MAX_XY);
            printf("%d %d\n", x, y);
        }
        printf("\n");
    }
    return 0;
}
#else
/* Graphical output. */
int main()
{
    int t;
    char buffer[MAX_XY-MIN_XY+1][MAX_XY-MIN_XY+2];
    for (t = 1; t <= CASES; t++)
    {
        int x0 = gen_int(MIN_XY, MAX_XY);
        int y0 = gen_int(MIN_XY, MAX_XY);
        int i, n = gen_int(MIN_N, MAX_N);
        memset(buffer, '.', sizeof(buffer));
        for (i = MIN_XY; i <= MAX_XY; i++)
            buffer[i-MIN_XY][MAX_XY-MIN_XY+1] = '\0';
        for (i = 0; i < n; i++)
        {
            int x = gen_int(MIN_XY, MAX_XY);
            int y = gen_int(MIN_XY, MAX_XY);
            buffer[y-MIN_XY][x-MIN_XY] = 'x';
            /* printf("%d %d\n", x, y); */
        }
        buffer[0-MIN_XY][0-MIN_XY] = 'S';
        buffer[y0-MIN_XY][x0-MIN_XY] = 'T';
        printf("Case %d:\n", t);
        for (i = MIN_XY; i <= MAX_XY; i++)
            printf("%s\n", buffer[i-MIN_XY]);
        printf("\n");
    }
    return 0;
}
#endif
